Setup

library(tidyverse)
library(forcats)
library(cowplot)
## 
## Attaching package: 'cowplot'
## The following object is masked _by_ '.GlobalEnv':
## 
##     save_plot
## The following object is masked from 'package:lubridate':
## 
##     stamp
library(ggupset)
library(RColorBrewer)
library(patchwork)
## 
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
## 
##     align_plots
library(pheatmap)
data <- targets::tar_read(merged_all_results)
# rename BLAST to BLAST97 to differentiate from BLAST100 (percentage identity in both cases)
data <- data |> mutate(Type = str_replace(Type, '^BLAST$', 'BLAST97'))
truth <- targets::tar_read(truth_set_data)
head(data)
## # A tibble: 6 × 11
##   Type    Query     Subject domain phylum class order family genus species OTU  
##   <chr>   <chr>     <chr>   <chr>  <chr>  <chr> <chr> <chr>  <chr> <chr>   <chr>
## 1 BLAST97 make_12s… 16S_v0… Eukar… Chord… Acti… Syng… Syngn… Phyl… Phyllo… ASV_1
## 2 BLAST97 make_12s… 16S_v0… Eukar… Chord… Acti… Gadi… Merlu… Merl… Merluc… ASV_3
## 3 BLAST97 make_12s… 16S_v0… Eukar… Chord… Acti… Syng… Syngn… Hipp… dropped ASV_5
## 4 BLAST97 make_12s… 16S_v0… Eukar… Chord… Acti… Labr… Labri… Hemi… Hemigy… ASV_…
## 5 BLAST97 make_12s… 16S_v0… Eukar… Chord… Lepi… Squa… Scinc… Trop… Tropid… ASV_…
## 6 BLAST97 make_12s… 16S_v0… Eukar… Chord… Chon… Chim… Chima… Hydr… dropped ASV_…
table(data$Type)
## 
##   BLAST100    BLAST97 Kraken_0.0 Kraken_0.1 Kraken_0.2 Kraken_0.3 Kraken_0.4 
##       9025      13893      55040      55040      55040      55040      55040 
## Kraken_0.5 Kraken_0.6 Kraken_0.7 Kraken_0.8 Kraken_0.9   Metabuli    MMSeqs2 
##      55040      55040      55040      55040      55040      32545      89856 
##     Mothur        NBC     Qiime2    VSEARCH 
##      87048      98280      26575      13331

Let’s remove the >0.2 Kraken runs, those are too strict

data <- data |> filter(!Type %in% c('Kraken_0.3', 'Kraken_0.4', 'Kraken_0.5', 'Kraken_0.6', 'Kraken_0.7', 'Kraken_0.8', 'Kraken_0.9'))

Made a mistake- Metabuli’s Database is misspelled

data <- data |> mutate(Subject = str_replace_all(Subject, pattern = '_ref.fasta', replacement=''))
table(data$Query)
## 
##                                                                                KWest_16S_PooledTrue.fa 
##                                                                                                 137155 
##   make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_Lulu_RESULTS_dada2_asv.fa 
##                                                                                                  49145 
## make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_noLulu_RESULTS_dada2_asv.fa 
##                                                                                                  49145 
##   make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_Lulu_RESULTS_dada2_asv.fa 
##                                                                                                  46533 
## make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_noLulu_RESULTS_dada2_asv.fa 
##                                                                                                  46533 
##                               make_12s_16s_simulated_reads_6-fakeGenes_GreenGenes_RESULTS_dada2_asv.fa 
##                                                                                                  39191 
##                                   make_12s_16s_simulated_reads_6-fakeGenes_Random_RESULTS_dada2_asv.fa 
##                                                                                                  39331 
##                     make_12s_16s_simulated_reads_7-Lutjanids_Mock_runEDNAFlow_12S_RESULTS_dada2_asv.fa 
##                                                                                                  12281 
##                     make_12s_16s_simulated_reads_7-Lutjanids_Mock_runEDNAFlow_16S_RESULTS_dada2_asv.fa 
##                                                                                                  12941 
##                           make_12s_16s_simulated_reads_8-Rottnest_runEDNAFLOW_12S_RESULTS_dada2_asv.fa 
##                                                                                                  50692 
##                           make_12s_16s_simulated_reads_8-Rottnest_runEDNAFLOW_16S_RESULTS_dada2_asv.fa 
##                                                                                                  52726

Check 12S results

table(data$Subject)
## 
##                                                    12s_v010_final.fasta 
##                                                                    8474 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_1.fasta 
##                                                                    7947 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                    7765 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_2.fasta 
##                                                                    7890 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                    7931 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_4.fasta 
##                                                                    7850 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_5.fasta 
##                                                                    7954 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                    7662 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_7.fasta 
##                                                                    7717 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_8.fasta 
##                                                                    8098 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                    8019 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_1.fasta 
##                                                                    8234 
## 12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_10.fasta 
##                                                                    8036 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                    8040 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_3.fasta 
##                                                                    8235 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_4.fasta 
##                                                                    8077 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                    8063 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_6.fasta 
##                                                                    8012 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_7.fasta 
##                                                                    8148 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_8.fasta 
##                                                                    8031 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_9.fasta 
##                                                                    8134 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_1.fasta 
##                                                                    7483 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_10.fasta 
##                                                                    7427 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_2.fasta 
##                                                                    7676 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_3.fasta 
##                                                                    7559 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_4.fasta 
##                                                                    7637 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_5.fasta 
##                                                                    7628 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_6.fasta 
##                                                                    7372 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_7.fasta 
##                                                                    7510 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_8.fasta 
##                                                                    7414 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_9.fasta 
##                                                                    7637 
##                                                    12S_v10_HmmCut.fasta 
##                                                                    5866 
##                                                     16S_v04_final.fasta 
##                                                                    9735 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_1.fasta 
##                                                                    8813 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                    8413 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_2.fasta 
##                                                                    8666 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                    8649 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_4.fasta 
##                                                                    8800 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_5.fasta 
##                                                                    8885 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                    8381 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_7.fasta 
##                                                                    8865 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_8.fasta 
##                                                                    8305 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                    8500 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_1.fasta 
##                                                                    9124 
##  16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_10.fasta 
##                                                                    9223 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                    9055 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_3.fasta 
##                                                                    8807 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_4.fasta 
##                                                                    9063 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                    9370 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_6.fasta 
##                                                                    8908 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_7.fasta 
##                                                                    9286 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_8.fasta 
##                                                                    9232 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_9.fasta 
##                                                                    9372 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_1.fasta 
##                                                                    8749 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_10.fasta 
##                                                                    8396 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_2.fasta 
##                                                                    8829 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_3.fasta 
##                                                                    8256 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_4.fasta 
##                                                                    8515 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_5.fasta 
##                                                                    8307 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_6.fasta 
##                                                                    8160 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_7.fasta 
##                                                                    8087 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_8.fasta 
##                                                                    8096 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_9.fasta 
##                                                                    8264 
##                                                    16S_v04_HmmCut.fasta 
##                                                                    6612 
##    c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                    1404 
##     c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                    1404 
##     c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                    1404 
##     c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                    1404 
##   c01_v03_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                    1404 
##   c01_v03_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                    1404
table(data$Subject)
## 
##                                                    12s_v010_final.fasta 
##                                                                    8474 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_1.fasta 
##                                                                    7947 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                    7765 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_2.fasta 
##                                                                    7890 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                    7931 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_4.fasta 
##                                                                    7850 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_5.fasta 
##                                                                    7954 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                    7662 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_7.fasta 
##                                                                    7717 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_8.fasta 
##                                                                    8098 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                    8019 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_1.fasta 
##                                                                    8234 
## 12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_10.fasta 
##                                                                    8036 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                    8040 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_3.fasta 
##                                                                    8235 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_4.fasta 
##                                                                    8077 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                    8063 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_6.fasta 
##                                                                    8012 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_7.fasta 
##                                                                    8148 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_8.fasta 
##                                                                    8031 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_9.fasta 
##                                                                    8134 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_1.fasta 
##                                                                    7483 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_10.fasta 
##                                                                    7427 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_2.fasta 
##                                                                    7676 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_3.fasta 
##                                                                    7559 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_4.fasta 
##                                                                    7637 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_5.fasta 
##                                                                    7628 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_6.fasta 
##                                                                    7372 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_7.fasta 
##                                                                    7510 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_8.fasta 
##                                                                    7414 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_9.fasta 
##                                                                    7637 
##                                                    12S_v10_HmmCut.fasta 
##                                                                    5866 
##                                                     16S_v04_final.fasta 
##                                                                    9735 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_1.fasta 
##                                                                    8813 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                    8413 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_2.fasta 
##                                                                    8666 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                    8649 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_4.fasta 
##                                                                    8800 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_5.fasta 
##                                                                    8885 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                    8381 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_7.fasta 
##                                                                    8865 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_8.fasta 
##                                                                    8305 
##     16S_v04_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                    8500 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_1.fasta 
##                                                                    9124 
##  16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_10.fasta 
##                                                                    9223 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                    9055 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_3.fasta 
##                                                                    8807 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_4.fasta 
##                                                                    9063 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                    9370 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_6.fasta 
##                                                                    8908 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_7.fasta 
##                                                                    9286 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_8.fasta 
##                                                                    9232 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_9.fasta 
##                                                                    9372 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_1.fasta 
##                                                                    8749 
##   16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_10.fasta 
##                                                                    8396 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_2.fasta 
##                                                                    8829 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_3.fasta 
##                                                                    8256 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_4.fasta 
##                                                                    8515 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_5.fasta 
##                                                                    8307 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_6.fasta 
##                                                                    8160 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_7.fasta 
##                                                                    8087 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_8.fasta 
##                                                                    8096 
##    16S_v04_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_9.fasta 
##                                                                    8264 
##                                                    16S_v04_HmmCut.fasta 
##                                                                    6612 
##    c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                    1404 
##     c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                    1404 
##     c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                    1404 
##     c01_v03_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                    1404 
##   c01_v03_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                    1404 
##   c01_v03_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                    1404
twelveS_data <- data |> filter(Subject == '12s_v010_final.fasta')
sixteenS_data <- data |> filter(Subject == '16S_v04_final.fasta')
table(twelveS_data$Query)
## 
##                                                                                KWest_16S_PooledTrue.fa 
##                                                                                                   1856 
##   make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_Lulu_RESULTS_dada2_asv.fa 
##                                                                                                    973 
## make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_noLulu_RESULTS_dada2_asv.fa 
##                                                                                                    973 
##   make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_Lulu_RESULTS_dada2_asv.fa 
##                                                                                                    654 
## make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_noLulu_RESULTS_dada2_asv.fa 
##                                                                                                    654 
##                               make_12s_16s_simulated_reads_6-fakeGenes_GreenGenes_RESULTS_dada2_asv.fa 
##                                                                                                    594 
##                                   make_12s_16s_simulated_reads_6-fakeGenes_Random_RESULTS_dada2_asv.fa 
##                                                                                                    600 
##                     make_12s_16s_simulated_reads_7-Lutjanids_Mock_runEDNAFlow_12S_RESULTS_dada2_asv.fa 
##                                                                                                    236 
##                     make_12s_16s_simulated_reads_7-Lutjanids_Mock_runEDNAFlow_16S_RESULTS_dada2_asv.fa 
##                                                                                                    193 
##                           make_12s_16s_simulated_reads_8-Rottnest_runEDNAFLOW_12S_RESULTS_dada2_asv.fa 
##                                                                                                    995 
##                           make_12s_16s_simulated_reads_8-Rottnest_runEDNAFLOW_16S_RESULTS_dada2_asv.fa 
##                                                                                                    746
table(sixteenS_data$Query)
## 
##                                                                                KWest_16S_PooledTrue.fa 
##                                                                                                   2875 
##   make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_Lulu_RESULTS_dada2_asv.fa 
##                                                                                                    744 
## make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_noLulu_RESULTS_dada2_asv.fa 
##                                                                                                    744 
##   make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_Lulu_RESULTS_dada2_asv.fa 
##                                                                                                    944 
## make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_noLulu_RESULTS_dada2_asv.fa 
##                                                                                                    944 
##                               make_12s_16s_simulated_reads_6-fakeGenes_GreenGenes_RESULTS_dada2_asv.fa 
##                                                                                                    598 
##                                   make_12s_16s_simulated_reads_6-fakeGenes_Random_RESULTS_dada2_asv.fa 
##                                                                                                    602 
##                     make_12s_16s_simulated_reads_7-Lutjanids_Mock_runEDNAFlow_12S_RESULTS_dada2_asv.fa 
##                                                                                                    187 
##                     make_12s_16s_simulated_reads_7-Lutjanids_Mock_runEDNAFlow_16S_RESULTS_dada2_asv.fa 
##                                                                                                    244 
##                           make_12s_16s_simulated_reads_8-Rottnest_runEDNAFLOW_12S_RESULTS_dada2_asv.fa 
##                                                                                                    774 
##                           make_12s_16s_simulated_reads_8-Rottnest_runEDNAFLOW_16S_RESULTS_dada2_asv.fa 
##                                                                                                   1079
table(sixteenS_data$Subject)
## 
## 16S_v04_final.fasta 
##                9735
twelveS_data_vs_12S_100 <- twelveS_data |> filter(Query == 'make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_Lulu_RESULTS_dada2_asv.fa')
sixteenS_data_vs_16S_100 <- sixteenS_data |> filter(Query == 'make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_Lulu_RESULTS_dada2_asv.fa' )
twelveS_data_vs_12S_100 |> select(Type, species) |> filter(species != 'dropped' &
                                                             !is.na(species)) |>
  group_by(Type) |> count(species) |> summarise(n = n()) |>
  ggplot(aes(x = Type, y = n, fill = n)) + geom_col() + coord_flip() + 
  theme_minimal() + 
  ylab('Count') + 
  ggtitle('12S: Species-level hits per classifier')

twelveS_data_vs_12S_100 |> select(Type, genus) |> filter(genus != 'dropped' &
                                                             !is.na(genus)) |>
  group_by(Type) |> count(genus) |> summarise(n = n()) |>
  ggplot(aes(x = Type, y = n, fill = n)) + geom_col() + coord_flip() + 
  theme_minimal() + 
  ylab('Count') + 
  ggtitle('12S: Genus-level hits per classifier')

twelveS_truth <- truth |> filter(Query == 'make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_Lulu_RESULTS_dada2_asv.fa') |> select(OTU, family, species) |> rename(True_OTU = OTU, True_family = family, True_species = species)
head(twelveS_truth)
## # A tibble: 6 × 3
##   True_OTU True_family    True_species            
##   <chr>    <chr>          <chr>                   
## 1 ASV_1    Syngnathidae   Phyllopteryx taeniolatus
## 2 ASV_2    Carcharhinidae Glyphis garricki        
## 3 ASV_3    Mullidae       Parupeneus barberinus   
## 4 ASV_4    Holocentridae  Myripristis vittata     
## 5 ASV_5    Scincidae      Tropidophorus hainanus  
## 6 ASV_6    Anatidae       Aythya nyroca
twelveS_data_vs_12S_100 |> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  mutate(Correct = True_species == species) |> 
  filter(species != 'dropped' & !is.na(species)) |> 
  group_by(Type) |> count(Correct) |> 
  ggplot(aes(x = fct_rev(fct_reorder2(Type, Correct, n)), fill = Correct, y = n))+ geom_col() +
  coord_flip() + theme_minimal() + xlab('Type') + 
  ggtitle('12S: Correct and incorrect species-level classifications (absolute)') +
  scale_fill_manual(values = c("#E69F00", "#56B4E9", "#009E73",
          "#F0E442", "#0072B2", "#D55E00", "#CC79A7"))

cols <- c('Correct species' = "#009E73", 'Correct genus'="#56B4E9", 'Correct family' = "#0072B2", 'Incorrect family' = "#E69F00", 'Incorrect genus'="#F0E442", 'Incorrect species'="#D55E00", 'NoHit'= "#CC79A7")
twelve_s_relative_plot <- twelveS_data_vs_12S_100 |> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  separate(True_species, into = c('True_Genus', 'True_Epiteth'), remove = FALSE)|> 
  mutate(species = na_if(species, 'dropped')) |> 
  mutate(genus = na_if(genus, 'dropped')) |> 

  mutate(CorrectSpecies = case_when(!is.na(species) & True_species == species ~ 'Correct species',
                              !is.na(species) & True_species != species ~ 'Incorrect species',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus == genus ~ 'Correct genus',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus != genus ~ 'Incorrect genus',
                              !is.na(family) & True_family == family ~ 'Correct family',
                              !is.na(family) & True_family != family ~ 'Incorrect family',
                              TRUE ~ NA)) |> 
  group_by(Type) |> 
  count(CorrectSpecies) |> 
  mutate(total = sum(n)) |> 
  mutate(missing = 99 - total) |> 
  group_modify(~ add_row(.x)) |> 
  group_modify(~ {
    .x |> mutate(new_col= max(missing, na.rm=TRUE)) |> 
      mutate(n = case_when(is.na(CorrectSpecies) & is.na(missing) ~ new_col,
                                  TRUE ~ n)) |> 
      select(-new_col)
  } ) |> 
  mutate(total = 99) |> 
  mutate(perc = n / total * 100) |> 
  mutate(CorrectSpecies = replace_na(CorrectSpecies, 'NoHit')) |> 
  mutate(CorrectSpecies = factor(CorrectSpecies, rev(c('Correct species', 'Correct genus', 'Correct family', 'Incorrect family', 'Incorrect genus', 'Incorrect species', 'NoHit')))) |> 
  ggplot(aes(x = fct_rev(fct_reorder2(Type, CorrectSpecies, n)), fill = CorrectSpecies, y = perc))+ 
  geom_col() +
  coord_flip() + 
  theme_minimal() + 
  ylab('Percentage') + xlab('Type') +
  ggtitle('12S: Correct and incorrect species-level classifications (relative)') +
  scale_fill_manual(name = 'Outcome', values = cols, breaks=names(cols))
twelve_s_relative_plot

## Calculate Upset-based species sightings

type_list <- twelveS_data_vs_12S_100 |> select(Type, species) |> unique() |> filter(!is.na(species) & species != 'dropped') |> 
  group_by(species) |> 
  summarize('Type' = list(Type))

a <- type_list |>
  ggplot(aes(x = Type)) + 
  geom_bar() +
  scale_x_upset(n_intersections = 12) +
  ggtitle('12S: Shared species') +
  ylab('Species')
a
## Warning: Removed 56 rows containing non-finite values (`stat_count()`).

type_list <- twelveS_data_vs_12S_100 |> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  filter(species == True_species) |> 
  filter(species != 'dropped' & !is.na(species)) |> 
  select(Type, species) |> unique() |> 
  group_by(species) |> 
  summarize('Type' = list(Type))

b <- type_list |>
  ggplot(aes(x = Type)) + 
  geom_bar() +
  scale_x_upset(n_intersections = 12) +
  ggtitle('12S: Shared correct species') +
  ylab('Species')
b
## Warning: Removed 27 rows containing non-finite values (`stat_count()`).

type_list <- twelveS_data_vs_12S_100 |> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  filter(species != True_species) |> 
  filter(species != 'dropped' & !is.na(species)) |> 
  select(Type, species) |> unique() |> 
  group_by(species) |> 
  summarize('Type' = list(Type))

c <- type_list |>
  ggplot(aes(x = Type)) + 
  geom_bar() +
  scale_x_upset(n_intersections = 12) +
  ggtitle('12S: Shared incorrect species') +
  ylab('Species')
c
## Warning: Removed 13 rows containing non-finite values (`stat_count()`).

a + b + c & ylim(c(0, 30)) & 
  theme(
  # Hide panel borders and remove grid lines
  panel.border = element_blank(),
  panel.grid.major = element_blank(),
  panel.background = element_blank(),
  panel.grid.minor = element_blank(),
  #panel.grid.major.y = element_line(),
  # Change axis line
  axis.line = element_line(colour = "black")
  )

Calculate FP/TP/TN/FN

add_scores <- function(twelveS_data_vs_12S_100_with_MaxTruth, twelveS_truth ) {
  twelveS_data_vs_12S_100_with_MaxTruth|> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  separate(True_species, into = c('True_Genus', 'True_Epiteth'), remove = FALSE)|> 
  mutate(species = na_if(species, 'dropped')) |> 
  mutate(genus = na_if(genus, 'dropped')) |> 

  mutate(CorrectSpecies = case_when(!is.na(species) & True_species == species ~ 'Correct species',
                              !is.na(species) & True_species != species ~ 'Incorrect species',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus == genus ~ 'Correct genus',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus != genus ~ 'Incorrect genus',
                              !is.na(family) & True_family == family ~ 'Correct family',
                              !is.na(family) & True_family != family ~ 'Incorrect family',
                              TRUE ~ NA)) |> 
  group_by(Type) |>
  summarise(TP = sum(str_detect(CorrectSpecies, pattern='Correct species'), na.rm=TRUE),
            FP = sum(str_detect(CorrectSpecies, pattern = 'Incorrect species'), na.rm=TRUE),
            TN = sum(str_detect(replace_na(CorrectSpecies,'NA'), pattern='NA') & is.na(True_species), na.rm=TRUE),
            FN = sum(is.na(species) & !is.na(True_species))) |> 
  mutate(sums = TP + FP + TN + FN) |> 
  mutate(missing = 99 - sums) |> 
  mutate(FN = FN + missing) |> 
  mutate(sums = TP + FP + TN + FN) |> 
  select(-c(missing, sums))
}
scores <- add_scores(twelveS_data_vs_12S_100, twelveS_truth)
precision <- function(TP, FP) {
  TP / (TP + FP )
}
recall <- function(TP, FN) {
  TP / (TP + FN)
}
f1 <- function(precision, recall) {
  2*precision * recall / (precision + recall)
}
f0.5 <- function(precision, recall) {
  ((1 + 0.5^2) * precision * recall) / (0.5^2 * precision + recall)
}
accuracy <- function(TP, FP, FN, TN) {
  (TN + TP) / (TN + TP + FP + FN)
}
scores <- scores |> rowwise() |> mutate(recall = recall(TP, FN), precision = precision(TP, FP),
                              f1 = f1(precision, recall), f0.5 = f0.5(precision, recall), accuracy = accuracy(TP, FP, FN, TN))
scores
## # A tibble: 11 × 10
## # Rowwise: 
##    Type          TP    FP    TN    FN recall precision    f1  f0.5 accuracy
##    <chr>      <int> <int> <int> <dbl>  <dbl>     <dbl> <dbl> <dbl>    <dbl>
##  1 BLAST100      59     6     0    34  0.634     0.908 0.747 0.836    0.596
##  2 BLAST97       48     8     0    43  0.527     0.857 0.653 0.762    0.485
##  3 Kraken_0.0    54    14     0    31  0.635     0.794 0.706 0.756    0.545
##  4 Kraken_0.1    47     5     0    47  0.5       0.904 0.644 0.778    0.475
##  5 Kraken_0.2    36     3     0    60  0.375     0.923 0.533 0.714    0.364
##  6 MMSeqs2       59    13     0    27  0.686     0.819 0.747 0.789    0.596
##  7 Metabuli      27     6     0    66  0.290     0.818 0.429 0.6      0.273
##  8 Mothur        41    20     0    38  0.519     0.672 0.586 0.635    0.414
##  9 NBC           42    19     0    38  0.525     0.689 0.596 0.648    0.424
## 10 Qiime2        31    46     0    22  0.585     0.403 0.477 0.429    0.313
## 11 VSEARCH       40    15     0    44  0.476     0.727 0.576 0.658    0.404
twelveS_scoreS_plot <- scores |> select(-c(TP, FP, FN, TN)) |> pivot_longer(-Type, names_to='Score') |>  ggplot(aes(x = fct_rev(fct_reorder(Type, value)), y = value, group=Score, color = Score, fill =Score)) + geom_line() + ylim(c(0, 1))  + theme_minimal_hgrid()+ theme(axis.text.x = element_text( angle = 45, hjust = 1)) + ylab('Score') + xlab('Tool') + ggtitle('12S scores')
twelveS_scoreS_plot

Scores heatmap

Let’s also make a heatmap from that

b <- scores$Type
m <- scores |> select(-Type) |> select(accuracy, recall, precision, f1, f0.5) |> as.matrix()
rownames(m) <- b
pheatmap(m, cluster_cols=FALSE, display_numbers = TRUE,
         color = colorRampPalette(brewer.pal(n = 7, name =
  "RdYlGn"))(100))

b <- scores$Type
m <- scores |> select(-Type) |> select(TP, FP, FN) |> as.matrix()
rownames(m) <- b
pheatmap(m, cluster_cols=FALSE, display_numbers = TRUE,
         color = colorRampPalette(brewer.pal(n = 7, name =
  "RdYlGn"))(100))

Metaclassifier

table(twelveS_data_vs_12S_100$Type)
## 
##   BLAST100    BLAST97 Kraken_0.0 Kraken_0.1 Kraken_0.2   Metabuli    MMSeqs2 
##         86         95         99         99         99         66         99 
##     Mothur        NBC     Qiime2    VSEARCH 
##         99         99         77         55

First, we count the per-OTU species hits

twelveS_data_vs_12S_100_maxCount <- twelveS_data_vs_12S_100 |>  
  mutate(species = na_if(species, 'dropped')) |> 
  filter(!is.na(species)) |> 
  #filter(! Type %in% c('Mothur', 'VSEARCH', 'Kraken_0.2', 'Qiime2', 'Metabuli', 'NBC', 'BLAST97', 'Kraken_0.0', 'Kraken_0.1')) |> 
  group_by(Query, Subject, OTU) |> 
  count(species) |> 
  # double check the truth
  #left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |> 
  #mutate(Truth = True_species == species) |> 
  # pull out the per-group highest n
  filter( n > 4) |> 
  slice_max(n, n=1, with_ties = FALSE) |> 
  mutate(Type = 'MaxCount', .before = 'Query') |> 
  select(-n)
twelveS_data_vs_12S_100_maxCount
## # A tibble: 57 × 5
## # Groups:   Query, Subject, OTU [57]
##    Type     Query                                          Subject OTU   species
##    <chr>    <chr>                                          <chr>   <chr> <chr>  
##  1 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_1 Phyllo…
##  2 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Sterco…
##  3 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Hemigy…
##  4 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Daptio…
##  5 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Engrau…
##  6 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Bathyr…
##  7 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Tripho…
##  8 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Ostrac…
##  9 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Nemipt…
## 10 MaxCount make_12s_16s_simulated_reads_5-BetterDatabase… 12s_v0… ASV_… Plesti…
## # ℹ 47 more rows
twelveS_data_vs_12S_100_with_MaxTruth <- twelveS_data_vs_12S_100 |> 
  bind_rows(twelveS_data_vs_12S_100_maxCount) #|>  
  #filter(! Type %in% c('Mothur', 'VSEARCH', 'Kraken_0.2', 'Qiime2', 'Metabuli', 'NBC', 'BLAST97', 'Kraken_0.0', 'Kraken_0.1')) 
maxTruth_scores <-  add_scores(twelveS_data_vs_12S_100_with_MaxTruth, twelveS_truth )
maxTruth_scores <- maxTruth_scores |> rowwise() |> mutate(recall = recall(TP, FN), precision = precision(TP, FP),
                              f1 = f1(precision, recall), f0.5 = f0.5(precision, recall), accuracy = accuracy(TP, FP, FN, TN))
maxTruth_scoreS_plot <- maxTruth_scores |> select(-c(TP, FP, FN, TN)) |> pivot_longer(-Type, names_to='Score') |>  ggplot(aes(x = fct_rev(fct_reorder(Type, value)), y = value, group=Score, color = Score, fill =Score)) + geom_line() + ylim(c(0, 1))  + theme_minimal_hgrid()+ theme(axis.text.x = element_text( angle = 45, hjust = 1)) + ylab('Score') + xlab('Tool') + geom_point() + ggtitle('12S scores')
maxTruth_scoreS_plot

Interestingly, just counting the labels is not good! It performs worse than BLAST.

Same for 16S

sixteenS_truth <- truth |> filter(Query == 'make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_16S_Lulu_RESULTS_dada2_asv.fa') |> select(OTU, family, species) |> rename(True_OTU = OTU, True_family = family, True_species = species)
head(sixteenS_truth)
## # A tibble: 6 × 3
##   True_OTU True_family    True_species            
##   <chr>    <chr>          <chr>                   
## 1 ASV_1    Syngnathidae   Phyllopteryx taeniolatus
## 2 ASV_2    Carcharhinidae Glyphis garricki        
## 3 ASV_3    Merlucciidae   Merluccius productus    
## 4 ASV_4    Mullidae       Parupeneus barberinus   
## 5 ASV_5    Syngnathidae   Hippocampus algiricus   
## 6 ASV_6    Eleotridae     Bostrychus sinensis
sixteenS_relative_plot <- sixteenS_data_vs_16S_100 |> left_join(sixteenS_truth, by = c('OTU' = 'True_OTU')) |>
 separate(True_species, into = c('True_Genus', 'True_Epiteth'), remove = FALSE)|> 
  mutate(species = na_if(species, 'dropped')) |> 
  mutate(genus = na_if(genus, 'dropped')) |> 

  mutate(CorrectSpecies = case_when(!is.na(species) & True_species == species ~ 'Correct species',
                              !is.na(species) & True_species != species ~ 'Incorrect species',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus == genus ~ 'Correct genus',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus != genus ~ 'Incorrect genus',
                              !is.na(family) & True_family == family ~ 'Correct family',
                              !is.na(family) & True_family != family ~ 'Incorrect family',
                              TRUE ~ NA)) |> 
  group_by(Type) |> 
  count(CorrectSpecies) |> 
  mutate(total = sum(n)) |> 
  mutate(missing = 99 - total) |> 
  group_modify(~ add_row(.x)) |> 
  group_modify(~ {
    .x |> mutate(new_col= max(missing, na.rm=TRUE)) |> 
      mutate(n = case_when(is.na(CorrectSpecies) & is.na(missing) ~ new_col,
                                  TRUE ~ n)) |> 
      select(-new_col)
  } ) |> 
  mutate(total = 99) |> 
  mutate(perc = n / total * 100) |> 
  mutate(CorrectSpecies = replace_na(CorrectSpecies, 'NoHit')) |> 
  mutate(CorrectSpecies = factor(CorrectSpecies, rev(c('Correct species', 'Correct genus', 'Correct family', 'Incorrect family', 'Incorrect genus', 'Incorrect species', 'NoHit')))) |> 
  ggplot(aes(x = fct_rev(fct_reorder2(Type, CorrectSpecies, n)), fill = CorrectSpecies, y = perc))+ 
  geom_col() +
  coord_flip() + 
  theme_minimal() + 
  ylab('Percentage') + xlab('Type') +
  ggtitle('16S: Correct and incorrect species-level classifications (relative)') +
  scale_fill_manual(name = 'Outcome', values = cols, breaks=names(cols))
sixteenS_relative_plot 

Calculate scores

scores <- add_scores(sixteenS_data_vs_16S_100, sixteenS_truth)
scores
## # A tibble: 11 × 5
##    Type          TP    FP    TN    FN
##    <chr>      <int> <int> <int> <dbl>
##  1 BLAST100      51     0     0    48
##  2 BLAST97       48     5     0    46
##  3 Kraken_0.0    52    15     0    32
##  4 Kraken_0.1    45    10     0    44
##  5 Kraken_0.2    35     6     0    58
##  6 MMSeqs2       60     5     0    34
##  7 Metabuli      16     3     0    80
##  8 Mothur        50    14     0    35
##  9 NBC           54    12     0    33
## 10 Qiime2        45    34     0    20
## 11 VSEARCH       43    12     0    44
scores <- scores |> rowwise() |> mutate(recall = recall(TP, FN), precision = precision(TP, FP),
                              f1 = f1(precision, recall), f0.5 = f0.5(precision, recall), accuracy = accuracy(TP, FP, FN, TN))
scores
## # A tibble: 11 × 10
## # Rowwise: 
##    Type          TP    FP    TN    FN recall precision    f1  f0.5 accuracy
##    <chr>      <int> <int> <int> <dbl>  <dbl>     <dbl> <dbl> <dbl>    <dbl>
##  1 BLAST100      51     0     0    48  0.515     1     0.68  0.842    0.515
##  2 BLAST97       48     5     0    46  0.511     0.906 0.653 0.784    0.485
##  3 Kraken_0.0    52    15     0    32  0.619     0.776 0.689 0.739    0.525
##  4 Kraken_0.1    45    10     0    44  0.506     0.818 0.625 0.728    0.455
##  5 Kraken_0.2    35     6     0    58  0.376     0.854 0.522 0.681    0.354
##  6 MMSeqs2       60     5     0    34  0.638     0.923 0.755 0.847    0.606
##  7 Metabuli      16     3     0    80  0.167     0.842 0.278 0.465    0.162
##  8 Mothur        50    14     0    35  0.588     0.781 0.671 0.733    0.505
##  9 NBC           54    12     0    33  0.621     0.818 0.706 0.769    0.545
## 10 Qiime2        45    34     0    20  0.692     0.570 0.625 0.591    0.455
## 11 VSEARCH       43    12     0    44  0.494     0.782 0.606 0.700    0.434
sixteenS_score_plot <- scores |> select(-c(TP, FP, FN, TN)) |> pivot_longer(-Type, names_to='Score') |>  ggplot(aes(x = fct_rev(fct_reorder(Type, value)), y = value, group=Score, color = Score, fill =Score)) + geom_line() + ylim(c(0, 1))  + theme_minimal_hgrid() + theme(axis.text.x = element_text( angle = 45, hjust = 1)) + ylab('Score') + xlab('Tool') +  ggtitle('16S scores')
sixteenS_score_plot 

b <- scores$Type
m <- scores |> select(-Type) |> select(accuracy, recall, precision, f1, f0.5) |> as.matrix()
rownames(m) <- b
pheatmap(m, cluster_cols=FALSE, display_numbers = TRUE,
         color = colorRampPalette(brewer.pal(n = 7, name =
  "RdYlGn"))(100))

b <- scores$Type
m <- scores |> select(-Type) |> select(TP, FP, FN) |> as.matrix()
rownames(m) <- b
pheatmap(m, cluster_cols=FALSE, display_numbers = TRUE,
         color = colorRampPalette(brewer.pal(n = 7, name =
  "RdYlGn"))(100))

## Calculate Upset-based species sightings

type_list <- sixteenS_data_vs_16S_100  |> select(Type, species) |> unique() |> filter(!is.na(species) & species != 'dropped') |> 
  group_by(species) |> 
  summarize('Type' = list(Type))

a <- type_list |>
  ggplot(aes(x = Type)) + 
  geom_bar() +
  scale_x_upset(n_intersections = 12) +
  ggtitle('16S: Shared species') +
  ylab('Species')
a
## Warning: Removed 47 rows containing non-finite values (`stat_count()`).

type_list <- sixteenS_data_vs_16S_100 |> left_join(sixteenS_truth,  by = c('OTU' = 'True_OTU')) |>
  filter(species == True_species) |> 
  filter(species != 'dropped' & !is.na(species)) |> 
  select(Type, species) |> unique() |> 
  group_by(species) |> 
  summarize('Type' = list(Type))

b <- type_list |>
  ggplot(aes(x = Type)) + 
  geom_bar() +
  scale_x_upset(n_intersections = 12) +
  ggtitle('16S: Shared correct species') +
  ylab('Species')
b
## Warning: Removed 25 rows containing non-finite values (`stat_count()`).

type_list <- sixteenS_data_vs_16S_100 |> left_join(sixteenS_truth, by = c('OTU' = 'True_OTU')) |>
  filter(species != True_species) |> 
  filter(species != 'dropped' & !is.na(species)) |> 
  select(Type, species) |> unique() |> 
  group_by(species) |> 
  summarize('Type' = list(Type))

c <- type_list |>
  ggplot(aes(x = Type)) + 
  geom_bar() +
  scale_x_upset(n_intersections = 12) +
  ggtitle('16S: Shared incorrect species') +
  ylab('Species')
c
## Warning: Removed 8 rows containing non-finite values (`stat_count()`).

a + b + c & ylim(c(0, 20)) & 
  theme(
  # Hide panel borders and remove grid lines
  panel.border = element_blank(),
  panel.grid.major = element_blank(),
  panel.background = element_blank(),
  panel.grid.minor = element_blank(),
  #panel.grid.major.y = element_line(),
  # Change axis line
  axis.line = element_line(colour = "black")
  )

Relative plots 12S 16S

sixteenS_relative_plot / twelve_s_relative_plot

(sixteenS_score_plot +geom_point() + theme(axis.title.x = element_blank()))/ (twelveS_scoreS_plot + geom_point())

12S exclusion databases

twelve_exclusions <- data |> filter(str_starts(Subject, '12s_v010_final.fasta_Taxonomies.CountedFams.txt_')) |> 
  filter(Query == 'make_12s_16s_simulated_reads_5-BetterDatabaseARTSimulation_runEDNAFLOW_12S_Lulu_RESULTS_dada2_asv.fa')
table(twelve_exclusions$Subject)
## 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_1.fasta 
##                                                                     837 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_10.fasta 
##                                                                     808 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_2.fasta 
##                                                                     822 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_3.fasta 
##                                                                     838 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_4.fasta 
##                                                                     826 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_5.fasta 
##                                                                     845 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_6.fasta 
##                                                                     786 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_7.fasta 
##                                                                     763 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_8.fasta 
##                                                                     852 
##    12s_v010_final.fasta_Taxonomies.CountedFams.txt_fifty_subset_9.fasta 
##                                                                     841 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_1.fasta 
##                                                                     907 
## 12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_10.fasta 
##                                                                     890 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_2.fasta 
##                                                                     864 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_3.fasta 
##                                                                     923 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_4.fasta 
##                                                                     856 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_5.fasta 
##                                                                     863 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_6.fasta 
##                                                                     856 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_7.fasta 
##                                                                     894 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_8.fasta 
##                                                                     885 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_seventy_subset_9.fasta 
##                                                                     891 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_1.fasta 
##                                                                     737 
##  12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_10.fasta 
##                                                                     733 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_2.fasta 
##                                                                     782 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_3.fasta 
##                                                                     763 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_4.fasta 
##                                                                     738 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_5.fasta 
##                                                                     757 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_6.fasta 
##                                                                     747 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_7.fasta 
##                                                                     729 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_8.fasta 
##                                                                     750 
##   12s_v010_final.fasta_Taxonomies.CountedFams.txt_thirty_subset_9.fasta 
##                                                                     758
twelve_exclusions_split <- twelve_exclusions |> separate(Subject, into = c('before', 'hit'), sep='.txt_') |> 
  # get rid of leftover non-subsetted databases
  filter(!is.na(hit)) |> 
  separate(hit, into=c('Database', 'after'), sep='_subset')
twelve_exclusions_split_averaged <- twelve_exclusions_split |> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  separate(True_species, into = c('True_Genus', 'True_Epiteth'), remove = FALSE)|> 
  mutate(species = na_if(species, 'dropped')) |> 
  mutate(genus = na_if(genus, 'dropped')) |> 

  mutate(CorrectSpecies = case_when(!is.na(species) & True_species == species ~ 'Correct species',
                              !is.na(species) & True_species != species ~ 'Incorrect species',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus == genus ~ 'Correct genus',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus != genus ~ 'Incorrect genus',
                              !is.na(family) & True_family == family ~ 'Correct family',
                              !is.na(family) & True_family != family ~ 'Incorrect family',
                              TRUE ~ NA)) |> 
  group_by(Type, Database, after) |>
  summarise(TP = sum(str_detect(CorrectSpecies, pattern='Correct species'), na.rm=TRUE),
            FP = sum(str_detect(CorrectSpecies, pattern = 'Incorrect species'), na.rm=TRUE),
            TN = sum(str_detect(replace_na(CorrectSpecies,'NA'), pattern='NA') & is.na(True_species), na.rm=TRUE),
            FN = sum(is.na(species) & !is.na(True_species))) |> 
  mutate(sums = TP + FP + TN + FN) |> 
  mutate(missing = 99 - sums) |> 
  mutate(FN = FN + missing) |> 
  mutate(sums = TP + FP + TN + FN) |> 
  select(-c(missing, sums)) |> 
  group_by(Type, Database) |> 
  summarise(mean_TP = mean(TP),
            mean_FP = mean(FP),
            mean_TN = mean(TN),
            mean_FN = mean(FN)) |> 
  rowwise() |> 
  mutate(recall = recall(mean_TP, mean_FN), 
         precision = precision(mean_TP, mean_FP),
         f1 = f1(precision, recall),
         f0.5 = f0.5(precision, recall),
         accuracy = accuracy(mean_TP, mean_FP, mean_FN, mean_TN)) 
## `summarise()` has grouped output by 'Type', 'Database'. You can override using
## the `.groups` argument.
## `summarise()` has grouped output by 'Type'. You can override using the
## `.groups` argument.
twelve_exclusions_split_averaged <- twelve_exclusions_split_averaged |> 
  mutate(Database = case_when ( Database == 'fifty' ~ '50%',
                               Database == 'seventy' ~ '70%',
                               Database == 'thirty' ~ '30%',
                               TRUE ~ Database))
f1_pl <- twelve_exclusions_split_averaged |> 
  ggplot(aes(x = Type, y = f1, group = Database, color = Database, fill = Database)) + 
  geom_point() +
  geom_line() +
  theme_minimal()
f0.5_pl <- twelve_exclusions_split_averaged |> 
  ggplot(aes(x = Type, y = f0.5, group = Database, color = Database, fill = Database)) + 
  geom_point() +
  geom_line() +
  theme_minimal()
precision_pl <- twelve_exclusions_split_averaged |> 
  ggplot(aes(x = Type, y = precision, group = Database, color = Database, fill = Database)) + 
  geom_point() +
  geom_line() +
  theme_minimal()
recall_pl <- twelve_exclusions_split_averaged |> 
  ggplot(aes(x = Type, y = recall, group = Database, color = Database, fill = Database)) + 
  geom_point() +
  geom_line() +
  theme_minimal()
(f1_pl / f0.5_pl / precision_pl / recall_pl) +  plot_layout(guides = 'collect')

Lets zero in on the precision and make boxplots with jitter dots

un_summarised_twelve <- twelve_exclusions_split |> left_join(twelveS_truth, by = c('OTU' = 'True_OTU')) |>
  separate(True_species, into = c('True_Genus', 'True_Epiteth'), remove = FALSE)|> 
  mutate(species = na_if(species, 'dropped')) |> 
  mutate(genus = na_if(genus, 'dropped')) |> 

  mutate(CorrectSpecies = case_when(!is.na(species) & True_species == species ~ 'Correct species',
                              !is.na(species) & True_species != species ~ 'Incorrect species',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus == genus ~ 'Correct genus',
                              !is.na(genus) & !is.na(True_Genus) & True_Genus != genus ~ 'Incorrect genus',
                              !is.na(family) & True_family == family ~ 'Correct family',
                              !is.na(family) & True_family != family ~ 'Incorrect family',
                              TRUE ~ NA)) |> 
  group_by(Type, Database, after) |>
  summarise(TP = sum(str_detect(CorrectSpecies, pattern='Correct species'), na.rm=TRUE),
            FP = sum(str_detect(CorrectSpecies, pattern = 'Incorrect species'), na.rm=TRUE),
            TN = sum(str_detect(replace_na(CorrectSpecies,'NA'), pattern='NA') & is.na(True_species), na.rm=TRUE),
            FN = sum(is.na(species) & !is.na(True_species))) |> 
  mutate(sums = TP + FP + TN + FN) |> 
  mutate(missing = 99 - sums) |> 
  mutate(FN = FN + missing) |> 
  mutate(sums = TP + FP + TN + FN) |> 
  select(-c(missing, sums)) |> 
  rowwise() |> 
  mutate(recall = recall(TP, FN), 
         precision = precision(TP, FP),
         f1 = f1(precision, recall),
         f0.5 = f0.5(precision, recall),
         accuracy = accuracy(TP, FP, FN, TN)) |> 
  mutate(Database = case_when ( Database == 'fifty' ~ '50%',
                               Database == 'seventy' ~ '70%',
                               Database == 'thirty' ~ '30%',
                               TRUE ~ Database))
## `summarise()` has grouped output by 'Type', 'Database'. You can override using
## the `.groups` argument.
un_summarised_twelve |> group_by(Type, Database) |> mutate(best = max(mean(precision))) |>
  ggplot(aes(x = fct_reorder(Type, best), group = interaction(Type, Database),  color=Database, y = precision)) +
  geom_boxplot(outlier.shape = NA) +
  coord_flip() +
  theme_minimal() +
  xlab('Type') +
  ylab('Precision') +
  geom_point(position = position_jitterdodge(), alpha=0.5)

un_summarised_twelve  |> group_by(Type, Database) |> mutate(best = max(mean(f0.5))) |>
  ggplot(aes(x = fct_reorder(Type, best), group = interaction(Type, Database), color=Database, y = f0.5)) +
  geom_boxplot(outlier.shape = NA) + 
  coord_flip() + 
  theme_minimal() + 
  xlab('Type') +
  ylab('f0.5') +
  ylim(c(0, 1)) +
  geom_point(position = position_jitterdodge(), alpha=0.5)

un_summarised_twelve  |> group_by(Type, Database) |> mutate(best = max(mean(recall))) |>
  ggplot(aes(x = fct_reorder(Type, best), group = interaction(Type, Database), color=Database, y = recall)) +
  geom_boxplot(outlier.shape = NA) + 
  coord_flip() + 
  theme_minimal() + 
  xlab('Type') +
  ylab('f0.5') +
  ylim(c(0, 1)) +
  geom_point(position = position_jitterdodge(), alpha=0.5)

un_summarised_twelve  |> 
  filter(Type %in% c('BLAST100', 'Kraken_0.0', 'Qiime2')) |> 
  ggplot(aes(x=Database, y = precision, fill=Type)) + #fill=factor(Database, levels=c('30%','50%','70%')))) + 
  geom_boxplot() +
  labs(fill='Type') + 
  ylab('Precision') + 
  theme_minimal()

false_positives <- un_summarised_twelve  |> 
  filter(Type %in% c('BLAST100', 'Kraken_0.0', 'Kraken_0.1', 'MMSeqs2')) |> 
  ggplot(aes(x=Database, y = FP/99*100, fill=Type)) + #fill=factor(Database, levels=c('30%','50%','70%')))) + 
  geom_boxplot(outlier.shape=NA) +
  labs(fill='Type') + 
  ylab('False positives (%)') + 
  geom_point(aes(color=Type), 
             position = position_jitterdodge(jitter.width = 0.2), 
             alpha=0.5,
             show.legend = FALSE)+
  theme_minimal()
false_positives

true_positives <- un_summarised_twelve  |> 
  filter(Type %in% c('BLAST100', 'Kraken_0.0', 'Kraken_0.1', 'MMSeqs2')) |> 
  ggplot(aes(x=Database, y = TP/99*100, fill=Type)) + #fill=factor(Database, levels=c('30%','50%','70%')))) + 
  geom_boxplot(outlier.shape=NA) +
  labs(fill='Type') + 
  ylab('True positives (%)') + 
  geom_point(aes(color=Type), 
           position = position_jitterdodge(jitter.width = 0.2), 
           alpha=0.5,
           show.legend = FALSE)+
  theme_minimal()
true_positives

false_positives/ true_positives + plot_layout(guides = 'collect') & coord_flip()